﻿using ML.Entity;
using ML.Plug;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Web.Mvc;

namespace ML.Web.Controllers
{
    /// <summary>
    /// 基类控制器
    /// </summary>
    public class BaseController : Controller
    {
        /// <summary>
        /// 重构方法(如果给前台响应日期时间调用此方法方法)
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public ContentResult JsonDateTime(object result)
        {
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
            return Content(JsonConvert.SerializeObject(result, Formatting.Indented, timeConverter));
        }

        /// <summary>
        /// 重构方法(如果给前台响应日期调用此方法方法)
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public ContentResult JsonDate(object result)
        {
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd" };
            return Content(JsonConvert.SerializeObject(result, Formatting.Indented, timeConverter));
        }

        /// <summary>
        /// 重构方法(如果给前台响应时间调用此方法方法)
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public ContentResult JsonTime(object result)
        {
            var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "HH:mm:ss" };
            return Content(JsonConvert.SerializeObject(result, Formatting.Indented, timeConverter));
        }

        /// <summary>
        /// 封装条件验证未通过的返回实体
        /// </summary>
        /// <returns></returns>
        public BaseResult<bool> ParrNoPass()
        {
            return new BaseResult<bool>(800, false);
        }
    }
}